package com.example.java.base.jdk8.optional;

import java.util.Date;
import java.util.Optional;

public class OptionalTest {
	public static void main(String[] args) {
		OptionalEntity nullObj=null;
		OptionalEntity notObj=new OptionalEntity();
		OptionalEntity notObj2 = new OptionalEntity(1,"21",new Date());

		System.out.println("null对象--->"+Optional.ofNullable(nullObj).isPresent());
		System.out.println("空值对象--->"+Optional.ofNullable(notObj).isPresent());
		System.out.println("非空值对象--->"+Optional.ofNullable(notObj2).isPresent());

	//	为空对象,重新创建新的对象
		Optional<OptionalEntity> nullObj1 = Optional.ofNullable(nullObj);
		OptionalEntity orElseGet = nullObj1.orElseGet(() -> new OptionalEntity());
		System.out.println("orElseGet = " + orElseGet);
	}
}